package com.example.zk1.login

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import com.example.common.mvvm.BaseViewActivity
import com.example.zk1.R
import com.example.zk1.databinding.ActivityLoginBinding
import com.example.zk1.register.RegisterActivity

class LoginActivity : BaseViewActivity<ActivityLoginBinding>() {
    lateinit var launcher: ActivityResultLauncher<Intent>
    override fun getLayout(): Int  = R.layout.activity_login

    override fun initView() {
        launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()){
            if(it.resultCode==102){
               val data =  it.data
                if(data!=null){
                    val username = data.getStringExtra("username")
                    val password = data.getStringExtra("password")
                    //给页面复制
                    binding.name = username
                    binding.pwd = password
                }
            }
        }

        binding.goReg.setOnClickListener {
            val intent = Intent(this,RegisterActivity::class.java)
            launcher.launch(intent)
        }
    }

    override fun initData() {

    }

}